package com.ny.service.impl;

import com.ny.mapper.UserMapper;
import com.ny.entity.Users;
import com.ny.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Users login(String username, String password) {

        return userMapper.findUserByUsernameAndPassword(username, password);
    }

    @Override

    public int allUserName(Users users) {
        return  userMapper.allUserName(users);
    }

    @Override
    public Users getUserById(int userId) {
        return userMapper.getUserById(userId);
    }

    @Override
    public boolean updatePhoneNumber(int userId, String newPhoneNumber) {
        Users user = new Users();
        user.setUserId(userId);
        user.setPhoneNumber(newPhoneNumber);
        int result = userMapper.updatePhoneNumber(user);
        return result > 0;
    }

    @Override
    public boolean updatePassword(int userId, String oldPassword, String newPassword) {
        Users user = getUserById(userId);
        if (user.getPassword().equals(oldPassword)) {
            user.setPassword(newPassword);
            int result = userMapper.updatePassword(user);
            return result > 0;
        }
        return false;
    }

    @Override
    public Users getCenterUserById(int userId) {
        return userMapper.getCenterUserById(userId);
    }

    @Override
    public int updateCenterPhoneNumber(int userId, String phoneNumber) {
        return userMapper.updateCenterUserPhoneNumber(userId,phoneNumber);
    }

    @Override
    public int updateCenterPassword(int userId, String newPassword) {
        return userMapper.updateCenterUserPassword(userId,newPassword);
    }

//    @Override
//    public boolean updateCenterPhoneNumber(Integer userId, String phoneNumber) {
//        return false;
//    }
//
//    @Override
//    public boolean updateCenterPassword(Integer userId, String newPassword) {
//        return false;
//    }
}
